{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "# Definition for a Node.\n",
    "class Node(object):\n",
    "    def __init__(self, val, children):\n",
    "        self.val = val\n",
    "        self.children = children\n",
    "\"\"\"\n",
    "class Solution(object):\n",
    "    def levelOrder(self, root):\n",
    "        \"\"\"\n",
    "        :type root: Node\n",
    "        :rtype: List[List[int]]\n",
    "        \"\"\"\n",
    "        elements = []\n",
    "        max_level = 0\n",
    "        \n",
    "        def recordNode(node, level):\n",
    "            if node is None:\n",
    "                return\n",
    "            if level > len(elements):\n",
    "                elements.append([node.val])\n",
    "            else:\n",
    "                elements[level-1].append(node.val)\n",
    "                \n",
    "            for child in node.children:\n",
    "                recordNode(child, level+1)\n",
    "        \n",
    "            return\n",
    "        \n",
    "        recordNode(root, 1)\n",
    "        \n",
    "        return elements"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
